<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>

<style>
	.licit{
		color: green;
	}
	.illegal{
		color: red;
	}
</style>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_right">
				<tr>
					<td><font style="font-size: 12px;"><strong>新增许可</strong></font>
					</td>
					<td width="25" height="26" align="left"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" class="table_right">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0"
							class="box_table" id="box_table2">
							<thead>
								<tr>
									<td height="36" class="box_table_even">代码：</td>
									<td class="box_table_odd">
										<input type="text" id="code" />
									<span class="star" >*</span>
									<span id="codeMsg"></span>
									</td>
								</tr>
								<tr>
									<td height="36" class="box_table_even">名称：</td>
									<td class="box_table_odd">
										<input type="text" id="name"/>
									<span class="star" >*</span>
									<span id="nameMsg"></span>
									</td>
								</tr>
								<tr>
									<td class="box_table_even">模块URL：</td>
									<td class="box_table_odd">
										<input type="text" id="moduleUrl" />
									</td>
								</tr>
								<tr>
									<td class="box_table_even">操作URL：</td>
									<td class="box_table_odd">
										<input type="text" size="90" id="operationUrl" />
										多个逗号隔开</td>
								</tr>
								<tr>
									<td class="box_table_even">排序号：</td>
									<td class="box_table_odd">
										<input type="text" id="orderNo"/>
										<span id="orderNoMsg"></span>
									</td>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>

						<table border="0" cellpadding="0" cellspacing="0"
							class="operation">
							<thead>
								<tr>
									<td height="24">&nbsp;</td>
								</tr>
							</thead>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_padding">
				<tr>
					<td height="21" align="right">
						<table align="left">
							<tr>
								<td width="50px"><a class="button" onclick="save()" href="javascript:void (0)"><span>保存</span></a></td>
								<td width="50px"><a class="button"
									href="javascript:void(window.history.back());"><span>返回</span></a></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<script src="${pageContext.request.contextPath}/lib/permissionUtils.js"></script>
<script>
	var zTreeObj = parent.treeFrame.$.fn.zTree.getZTreeObj("permission_tree");
	function save() {
		let code = $("#code").val();
		let name = $("#name").val();
		let moduleUrl = $("#moduleUrl").val();
		let operationUrl = $("#operationUrl").val();
		let orderNo = $("#orderNo").val();
		let pid = "${pid}";

		//最终校验
		let flag = lashVerifyPermission(code,name,orderNo);
		if (!flag){
			alert("请输入正确的合法数据");
			return;
		}

		var json = {
			"code":code,
			"name":name,
			"moduleUrl":moduleUrl,
			"operationUrl":operationUrl,
			"orderNo":orderNo,
			"pid":pid,
		}
		$.post("${pageContext.request.contextPath}/permission?method=addPermission",json,function (data) {
			if (data.code=="200"){
				//操作成功
				let parentNode = zTreeObj.getSelectedNodes()[0];//父节点的数据(就是当前选中的节点)
				json.id= data.data;
				zTreeObj.addNodes(parentNode, json);
				window.history.back();//返回历史上一步
			}else {
				alert(data.message);
			}
		},"json")
		//校验名称重复

	}





</script>